fix(cli): surface actionable re-auth message on revoked cloud API key#11
Open
andrei-hasna wants to merge 1 commit into
Open
fix(cli): surface actionable re-auth message on revoked cloud API key#11andrei-hasna wants to merge 1 commit into
andrei-hasna wants to merge 1 commit into
Conversation
Cloud create/list (and every async CLI action) previously crashed with a raw CloudHttpError stack trace when HASNA_INSTRUCTIONS_API_KEY was revoked or invalid: program.parse does not await/catch async action rejections and list/add had no try/catch, so the managed-rule update path was blocked. Switch the CLI to program.parseAsync with a single top-level handler and add formatCliError + isCloudAuthError helpers. 401/403 auth failures now print a clear re-auth path (rotate HASNA_INSTRUCTIONS_API_KEY, or unset both env vars to fall back to the local store) instead of a raw stack trace. Non-auth errors are unchanged. Adds unit + create/list revoked-key coverage. Refs: todos OPE80-00013
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Cloud
list/add(config create) — and every async CLI action — no longer crash with a rawCloudHttpErrorstack trace when the cloud API key is revoked or invalid. Auth failures (HTTP 401/403) now print a clear, actionable re-auth message and exit 1.Why
On the Infinity global-rule update,
@hasna/instructionsin cloud mode (HASNA_INSTRUCTIONS_API_URL+HASNA_INSTRUCTIONS_API_KEYset) failed the list/add/create paths withCloudHttpError 401 API key has been revoked, blocking the managed-rule update (which had to fall back to@hasna/configs).Two root causes:
program.parse, which does not await or catch async action rejections — so a rejected action surfaced as an unhandled-promise raw stack trace.listandadd(and several other actions) had notry/catchat all.Fix
program.parseAsync(...)with a single top-level handler that routes every uncaught action error throughformatCliError.isCloudAuthError(401/403CloudHttpError) andformatCliErrorinsrc/data/config-store.ts. Auth failures now render:HASNA_INSTRUCTIONS_API_KEY, or unset both env vars to use the local store.catchblocks throughformatCliErrortoo (non-auth errors unchanged).Tests
describe("revoked / invalid API key handling")insrc/data/config-store.test.ts:isCloudAuthErrormatching,formatCliErroroutput, and revoked-key coverage for both the cloud list and create paths.bun test: 287 pass / 0 fail (clean env).tsc --noEmit: clean.listandaddnow print the re-auth message and exit 1; valid-key and local-mode paths unaffected.Refs: todos OPE80-00013